//
//  MSHeroAvatarNode.m
//  MagicSword
//
//  Created by Netease on 15/11/17.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSHeroAvatarNode.h"
#import "MSHeroManager.H"

@implementation MSHeroAvatarNode {
    SKSpriteNode *_selectdNode;
    SKSpriteNode *_avatarNode;
}

- (id)initWithHeroInfo:(MSHeroInfo *)info {
    
    self = [super initWithImageNamed:@"avatar_background"];
    if (self) {
        float heroSize = 50;
        _heroInfo = info;
        self.size = CGSizeMake(heroSize, heroSize);
        self.zPosition = 3;
        
        _avatarNode = [SKSpriteNode spriteNodeWithTexture:info.avatarTexture];
        _avatarNode.zPosition = 4;
        _avatarNode.size = CGSizeMake(heroSize, heroSize);
        _avatarNode.position = CGPointMake(0, 0);
        [self addChild:_avatarNode];
        
        _selectdNode = [SKSpriteNode spriteNodeWithImageNamed:@"main_hero_selected"];
        _selectdNode.zPosition = 5;
        _selectdNode.position = CGPointMake(heroSize/2-5, -heroSize/2+5);
        [_selectdNode setHidden:YES];
        [self addChild:_selectdNode];
    }
    return self;
}

- (void)setSize:(CGSize)size {
    [super setSize:size];
    _avatarNode.size = size;
}

- (void)setName:(NSString *)name {
    [super setName:name];
    [_avatarNode setName:name];
    [_selectdNode setName:name];
}

- (void)setSelected:(BOOL)isSelected {
    [_selectdNode setHidden:!isSelected];
}

@end
